var json_list = {};

//function init_result(data)
//{
	//json_list = data;
	//基本表格数据填充
	//base_table("C01_FE23HT");
	//简单列表数据填充
	//list_table("C01_A682FV");
//}

function init_result(data)
{
	var temINF_EN_NAME = "";
	json_list = data;
	var msg = json_list["APP_USER_ZXY"];
	//查询失败
    if (Call_QryResult(msg) == false)
        return false;		
	$.each(msg,function(i, obj) {
		if(temINF_EN_NAME != obj.INF_EN_NAME)
		{
			if(obj[GetLowUpp("item_type")] == "1")
			{
				base_table(obj.INF_EN_NAME);
			}
			else if(obj[GetLowUpp("item_type")] == "2")
			{
				list_table(obj.INF_EN_NAME);
			}
			temINF_EN_NAME = obj.INF_EN_NAME;
		}		
	});
	page_end();
}

//特殊函数处理
function special_deal(i,dt_name,return_name,objValue)
{
	var json_tag = {};
	var o_text = "";
	json_tag[GetLowUpp("iIndex")] = i;
	json_tag[GetLowUpp("dt_name")] = dt_name;
	json_tag[GetLowUpp("return_name")] = return_name;
	json_tag[GetLowUpp("obj_value")] = objValue;	
	o_text = callbackFuctionRt("Biz_special_fun",json_tag);
	return o_text;
}

function special_html(i,dt_name,return_name,objValue)
{
	var json_tag = {};
	var o_text = "";
	json_tag[GetLowUpp("iIndex")] = i;
	json_tag[GetLowUpp("dt_name")] = dt_name;
	json_tag[GetLowUpp("return_name")] = return_name;
	json_tag[GetLowUpp("obj_value")] = objValue;	
	o_text = callbackFuctionRt("Biz_special_html",json_tag);
	return o_text;
}


function Is_Float(input)
{
	var regstr = "^\\d+(\\.\\d+)?$";
    var reg = new RegExp(regstr);
	return reg.test(input);
}

//是否特殊字段中文转义，利用APP_USER_ZXY接口
function IS_URLENCODE(dt_nam,return_name,objValue)
{
	var objResult = "";
	var msg = json_list["APP_USER_ZXY"];
	if(typeof(msg) !=  "undefined"){
		$.each(msg,function(i, obj) {			
			if(obj["INF_EN_NAME"].toString() == dt_nam && obj["RETURN_NAME"].toString() == return_name)
			{
				if(obj["IS_URLENCODE"].toString() == "1")
				{
					objResult = s_decode(objValue);
					return objResult;
				}
				else
				{
					objResult = objValue;
					return objResult;
				}
			}
		});
	}
	else
		objResult = objValue;
	return objResult;
}

//简单列表数据填充
function list_table(tb_name)
{
	var msg = null;
	if(tb_name.length > 0 && tb_name.substring(tb_name.length - 1,tb_name.length) == "_")
		msg = json_list[tb_name.substring(0,tb_name.length - 1)];
	else
		msg = json_list[tb_name];
	if($("[name='"+tb_name+"RRR']").length>0){ 
		var objTag = $("[name='"+tb_name+"RRR']");		
		$.each(msg,function(i, obj) {			
			var objTagNew = base_child_table(i,obj,tb_name,objTag);		
			var row_index = $(objTag)[0].rowIndex;
			var $tr = $(objTag).parent().find("tr").eq(row_index);
			$tr.before(objTagNew);
		});
		$(objTag).remove();
	}
}

//当前元素数据填充,并且合并第一列
//function base_child_table_2(msg,dt_name,objTag,iIndex,ALength)
//{
//	var NewO = document.createElement("tr")
//	$(NewO).html(objTag.html());
//    for(var obj in msg)
//	{
//    	var o_text = special_deal(dt_name,obj,IS_URLENCODE(dt_name,obj,msg[obj]));    	
//    	$(NewO).find("[name='"+dt_name+obj+"']").find("span").html(o_text);  	
//	}
//    if(iIndex == "0")
//    {
//    	var iCol = $(NewO).find("td").eq(0).attr("rowspan");
//    	$(NewO).find("td").eq(0).attr("rowspan",ALength);
//    }
//    else
//    {
//    	$(NewO).find("td").eq(0).remove();
//    }
//    return NewO;
//}

//当前元素数据填充
function base_child_table(i,msg,dt_name,objTag)
{
	var NewO = document.createElement("tr")
	$(NewO).html(objTag.html());
    for(var obj in msg)
	{
    	var o_text = special_deal(i,dt_name,obj,IS_URLENCODE(dt_name,obj,msg[obj])); 
    	$(NewO).find("[name='"+dt_name+obj+"']").find("span").text(o_text);  

    	var o_html = special_html(i,dt_name,obj,IS_URLENCODE(dt_name,obj,msg[obj])); 
    	if(o_html != "")
    		$(NewO).find("[name='"+dt_name+obj+"']").find("span").html(o_html); 
	}
    return NewO;
}

//模板元素数据填充
function base_temp_table(i,msg,dt_name)
{
	for(var obj in msg)
	{
    	var o_text = special_deal(i,dt_name,obj,IS_URLENCODE(dt_name,obj,msg[obj]));    	
    	$("[name='"+dt_name+obj+"']").text(o_text);
    	
    	var o_html = special_html(i,dt_name,obj,IS_URLENCODE(dt_name,obj,msg[obj]));
    	if(o_html != "")
    		$("[name='"+dt_name+obj+"']").html(o_html);
	}
}

//基本表格数据填充
function base_table(dt_name)
{
	var msg = null;
	if(dt_name.length > 0 && dt_name.substring(dt_name.length - 1,dt_name.length) == "_")
		msg = json_list[dt_name.substring(0,dt_name.length - 1)];
	else
		msg = json_list[dt_name];
    for(var obj in msg[0])
	{
    	//特殊表特殊字段中文转义
    	var o_text = special_deal(0,dt_name,obj,IS_URLENCODE(dt_name,obj,msg[0][obj]));    	
    	$("[name='"+dt_name+obj+"']").text(o_text);
    	//判断该字段值是否有重复显示
    	for(var i = 1; i < 10; i ++)
    	{
    		if($("[name='"+dt_name+"00"+i+obj+"']").length>0){ 
    			$("[name='"+dt_name+"00"+i+obj+"']").text(o_text);
    		}else{ 
    			break;
    		} 
    	}
    	
    	var o_html = special_html(0,dt_name,obj,IS_URLENCODE(dt_name,obj,msg[0][obj])); 
    	if(o_html != "")
    		$("[name='"+dt_name+obj+"']").html(o_html);
	}
}